<script>
$(document).ready(function(){

 var dlg = $("div#dlg{$module.name}.dialog");
 var table = $("table.dataTable#{$module.name}");

  $("a.add.{$module.name}").bind('click',function(e){
	 e.preventDefault();
	 var frm = $(dlg).find("form");
	 $(dlg).dialog("open");
	 var data = {};
	 data.idCategoria = -1;
	 data.nombre = "";
	 data.codigo = "";
	 data.descripcion = "";
	 $(frm).data("callback", function(){
		$(table).dataTable('loadData');
	 });

	 loadForm(frm,data);
  });
  
  $(table).dataTable();

  $(table).find("tbody a.edit").live('click',function(e){
	 e.preventDefault();
	 var data = $(this).parents("tr").eq(0).data("data");
	 var frm = $(dlg).find("form");
	 $(dlg).dialog("open");
	 $(frm).data("callback", function(){
		$(table).dataTable('loadData');
	 });
	 loadForm(frm,data);
  });
  
  $(table).find("tbody a.delete").live('click',function(e){
	 e.preventDefault();
	 var tr = $(this).parents("tr").get(0);
	 
	 data = {};
	 data.ajax= 'ajax';
	 data.idEmpresa = $(tr).data('data').idEmpresa;
	 
	 $.ajax({ url:'index.php/{$module.name}/delete', data: data, dataType:'json',
				success: function(response){
					$(tr).remove();
				}});
	 
  });

});
</script>

<a href="#" id="add" class="add {$module.name}" ><img src="files/images/add.png" /></a>

<table class="dataTable" id="{$module.name}">
  <thead>
    <tr>
      <th>
		  <a href="index.php/{$module.name}/list?" class="onload" root="response.data" />
      </th>
      {foreach from=$module.table.fields item="c"}
	      <th width="{$c.width}">{$c.label}</th>
      {/foreach}
      <th></th>
    </tr>
  </thead>
  <tbody>
	<tr class="model">
	  <td class="" ></td>

      {foreach from=$module.table.fields item="c"}
	      <td width="{$c.width}" class="{$c.name}"></td>
      {/foreach}
	  <td class="" >
		<a href="#" class="edit"><img src="files/images/edit.png" /></a>
		<a href="#" class="edit"><img src="files/images/delete.png" /></a>
	  </td>
	</tr>
  </tbody>
</table>

{include file="__module/__form.html"}
